/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.jitag.proc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sk.jp.commons.utils.BackgroundProcess;
import sk.jp.jitag.util.Msg;

/**
 * Runs release unused allocated memory - <i>garbage collector</i>.
 */
public class GarbageCollectorProcess extends BackgroundProcess {

    private static final Logger log = LoggerFactory.getLogger(GarbageCollectorProcess.class);

    //----------------------------------------------------------------------

    public GarbageCollectorProcess(StateHandler... stateHandler) {
        super(stateHandler);
    }

    //----------------------------------------------------------------------

    public boolean isCancellable() {
        return false;
    }

    public String getInfo() {
        return Msg.garbageCollectorProcessInfo.value(); //free allocated memory / uvolnovanie alokovanej pamate
    }

    public void run() {
        try {
            processStarted();

            //noinspection CallToSystemGC
            System.gc();

            processFinished();
        }catch(Throwable t){
            log.error("Unexpected exception during performing background process", t);
            processFinishedWithError(t);
        }
    }
}